package date;

import java.time.LocalDateTime;
import java.util.*;

/**
 * 日期
 *
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/12/20 15:32
 */
public class DateDemo {
    public static void main(String[] args) {
        // Date date = new Date(0);
        // System.out.println(date);
        // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        // String format = sdf.format(date);
        // System.out.println(format);
        // // 生成1970-2000之前的随机日期，并升序排序
        // Set<LocalDate> set = new TreeSet<>();
        // long start = LocalDate.of(1970, 1, 1).toEpochDay();
        // long end = LocalDate.of(2000, 1, 1).toEpochDay();
        //
        // Random random = new Random();
        // for (int i = 0; i < 10; i++) {
        //     long randomDay = start + random.nextInt((int) (end - start));
        //     LocalDate localDate = LocalDate.ofEpochDay(randomDay);
        //     set.add(localDate);
        // }
        // for (LocalDate localDate : set) {
        //     System.out.println(localDate);
        // }
        // getTomorrow();
        // getTomorrowJava8();
        dateBase();
    }

    // Date类的基本用法
    private static void dateBase() {
        Date date = new Date();
        // 当前年份，需+1900
        System.out.println(date.getYear() + 1900);
        // 当前月份，需+1
        System.out.println(date.getMonth() + 1);
        // 当前日，1~31
        System.out.println(date.getDate());
        // 标准GMT时区
        System.out.println(date.toGMTString());
        // 本地时区
        System.out.println(date.toLocaleString());
    }

    private static void getTomorrowJava8() {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime tomorrow = now.plusDays(1);
        System.out.println(tomorrow);
    }

    private static void getTomorrow() {
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, 1);
        Date tomorrow = calendar.getTime();
        System.out.println(tomorrow);
    }
}
